package com.hzdl.flower.controller;

import com.hzdl.flower.bean.Admin;
import com.hzdl.flower.service.AenterService;
import com.hzdl.flower.util.HzdlJsonAjax;
import com.hzdl.flower.vo.AdminVo;
import com.hzdl.flower.vo.LogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("enter")
public class AEnterController {
    @Autowired
    private AenterService as;

    @RequestMapping("enterInit")//登录界面初始化
    public String enterInit(){
        return "admin/login";
    }

    @RequestMapping("admin")//登录
    @ResponseBody
    public HzdlJsonAjax admin(AdminVo adminVo, LogVo logVo, Model model, HttpServletRequest request){

        Admin nameAndId = as.findNameAndId(adminVo);
        String ip = request.getRemoteAddr();
        logVo.setLogip(ip);
        int i = as.add(logVo);
        if (i==0){
            return null;
        }else {
            model.addAttribute("nameAndId",nameAndId);

            return new HzdlJsonAjax("0!",0,nameAndId);
        }

    }

    @RequestMapping("indexInit")//登录
    public String pageInit(){

            return "admin/index";//成功返回主页面

    }



}
